/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server.dao;

import java.util.List;
import server.domain.Client;

/**
 *
 * @author fillipe
 */
public class ClientDAO extends GenericDAO<Client> {

    public ClientDAO() {
        super(Client.class);
    }

    public Client getByCPF(String cpf) throws Exception {
        return (Client) getOne("from Client c where c.cpf = ?", cpf);
    }

    public List<Client> getByName(String name) throws Exception {
        return list("from Client c where c.name like ? order by c.name asc", name + "%");
    }

    public boolean existClientOrder(Long clientId) throws Exception {
        List result = list("from Order o where o.client.id = ?", clientId);
        return !result.isEmpty();
    }
}
